/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package cn.lixunims.ims.modular.order.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.lixunims.ims.modular.bill.param.ImsBillHeaderIdParam;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.lixunims.common.annotation.CommonLog;
import cn.lixunims.common.pojo.CommonResult;
import cn.lixunims.ims.modular.order.entity.ImsOrderHeader;
import cn.lixunims.ims.modular.order.param.ImsOrderAddParam;
import cn.lixunims.ims.modular.order.param.ImsOrderHeaderIdParam;
import cn.lixunims.ims.modular.order.param.ImsOrderHeaderPageParam;
import cn.lixunims.ims.modular.order.service.ImsOrderHeaderService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;

/**
 * 订单控制器
 *
 * @author YouDong
 * @date  2024/09/19 14:28
 */
@Tag(name = "订单控制器")
@RestController
@Validated
public class ImsOrderController {

    @Resource
    private ImsOrderHeaderService imsOrderHeaderService;

    /**
     * 获取订单头分页
     *
     * @author YouDong
     * @date  2024/09/19 14:28
     */
    @Operation(summary = "查询单据分页")
    @SaCheckPermission("/ims/order/page")
    @GetMapping("/ims/order/page")
    public CommonResult<Page<ImsOrderHeader>> page(ImsOrderHeaderPageParam imsOrderHeaderPageParam) {
        return CommonResult.data(imsOrderHeaderService.page(imsOrderHeaderPageParam));
    }

    /**
     * 保存订单
     *
     * @author YouDong
     * @date  2024/09/19 14:28
     */
    @Operation(summary = "保存订单")
    @CommonLog("保存订单")
    @SaCheckPermission("/ims/order/save")
    @PostMapping("/ims/order/save")
    public CommonResult<String> save(@RequestBody @Valid ImsOrderAddParam imsOrderAddParam) {
        imsOrderHeaderService.save(imsOrderAddParam);
        return CommonResult.ok();
    }


    /**
     * 获取单据详情
     *
     * @author YouDong
     * @date  2024/09/19 14:28
     */
    @Operation(summary = "获取单据详情")
    @SaCheckPermission("/ims/order/detail")
    @GetMapping("/ims/order/detail")
    public CommonResult<ImsOrderAddParam> detail(@Valid ImsOrderHeaderIdParam imsOrderHeaderIdParam) {
        return CommonResult.data(imsOrderHeaderService.detail(imsOrderHeaderIdParam));
    }


    /**
     * 生成流水号
     *
     * @author YouDong
     * @date  2024/09/19 14:28
     */
    @Operation(summary = "生成流水号")
    @SaCheckPermission("/ims/order/detail")
    @GetMapping("/ims/order/getBillNo")
    public CommonResult<String> getBillNo(String billType) {
        return CommonResult.data(imsOrderHeaderService.getBillNo(billType));
    }

    /**
     * 删除单据
     * @author YouDong
     * @date 2024/10/25
     */
    @Operation(summary = "删除单据")
    @SaCheckPermission("/ims/order/delete")
    @DeleteMapping("/ims/order/delete")
    public CommonResult delete(@Valid @RequestBody ImsOrderHeaderIdParam imsOrderHeaderIdParam) {
        imsOrderHeaderService.delete(imsOrderHeaderIdParam);
        return CommonResult.ok();
    }

}
